package com.jiaquyun.jcyx.main.mine

import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentStatePagerAdapter
import com.blankj.utilcode.util.ActivityUtils
import com.jiaquyun.jcyx.R
import com.module.lemlin.owner.OwnerAbstractActivity
import kotlinx.android.synthetic.main.activity_mine_coupon.*

class MineCouponActivity : OwnerAbstractActivity() {

    companion object {
        val tabs = mutableListOf("未使用", "已使用", "已过期")
        fun open() {
            ActivityUtils.startActivity(MineCouponActivity::class.java)
        }
    }

    override val layoutResId: Int
        get() = R.layout.activity_mine_coupon

    override fun stateBar(): StatusBar {
        return StatusBar(isLightMode = true, color = R.color.white, view = flMineCouponBar)
    }

    override fun initView() {

        ivAppBack.setOnClickListener { finish() }

        val pagerAdapter = object : FragmentStatePagerAdapter(
            supportFragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
        ) {
            override fun getItem(position: Int): Fragment =
                MineCouponFragment.newInstance(position)

            override fun getCount(): Int = tabs.size

            override fun getPageTitle(position: Int): CharSequence =
                tabs[position]

            override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {}
        }

        tabMineCouponKind.apply {
            for (item in tabs) {
                addTab(newTab().setText(item))
            }
        }.setupWithViewPager(vpMineCouponBody.apply {
            adapter = pagerAdapter
        })
    }
}